package com.usian.article.controller.v1;

import com.usian.apis.article.AuthorControllerApi;
import com.usian.article.service.AuthorService;
import com.usian.model.article.pojos.ApAuthor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/v1/author")
public class AuthorController implements AuthorControllerApi {

    @Autowired
    private AuthorService authorService;

    @GetMapping("/findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable("id") Integer id) {
        return authorService.getById(id);
    }

    @PostMapping("/save")
    @Override
    public ApAuthor save(@RequestBody ApAuthor apAuthor) {
        apAuthor.setCreatedTime(new Date());
        authorService.save(apAuthor);
        return apAuthor;
    }
}
